package com.song.config;

import com.song.pojo.UserModel;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

//用户详细信息

public class CustomUserDetails implements UserDetails {
    private String id;
    private String username;
    private String nickname;
    private String portrait;
    private String password;
    private Integer type;
    private String Token;

    public Integer getType() {
        return type;
    }

    public CustomUserDetails(String uId, String username, String password, String nickname, String portrait, Integer type) {
        this.id = uId;
        this.username = username;
        this.nickname = nickname;
        this.portrait = portrait;
        this.password = password;
        this.type = type;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        添加权限
        List<GrantedAuthority> authorities = new ArrayList<>();
        if (type == 0) {
            authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
            authorities.add(new SimpleGrantedAuthority("ROLE_MANAGER"));
            authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        } else if (type == 2) {

            authorities.add(new SimpleGrantedAuthority("ROLE_MANAGER"));
            authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        } else {

            authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        }
        return authorities;
    }


    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    /**
     * 账户是否未过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账户是否未锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否未过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账户是否激活
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    public String getId() {
        return id;
    }

    public String getNickname() {
        return nickname;
    }

    public String getPortrait() {
        return portrait;
    }

    public void setToken(String token) {

        this.Token = token;

    }

    public String getToken() {

        return this.Token;
    }

    public void setPassword(String passwrod) {

        this.password = passwrod;
    }
}